package exam.test15;

import java.util.HashMap;
import java.util.Map;
import java.util.TreeSet;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Endstart
 * Date: 2020-12-12
 * Time: 10:33
 */
public class NRSA {
    private Map<String, TownStatistics> incidents = new HashMap<String, TownStatistics>();

    /**
     * @param townName     - value of town name
     * @param incidentType - a value which can be "accident" or "fatality"
     */
    public void addIncident(String townName, String incidentType) {
        TownStatistics townStatistics = incidents.get(townName);
        if (townStatistics == null) {
            townStatistics = new TownStatistics(townName);
            incidents.put(townName, townStatistics);
        }

        if (incidentType.equalsIgnoreCase("incidentType")) {
            townStatistics.incrementAccidents();
        } else if (incidentType.equalsIgnoreCase("fatality")) {
            townStatistics.incrementFatalities();
        }
    }

    public TreeSet<TownStatistics> reportStatistics() {
        TreeSet<TownStatistics> set = new TreeSet<>();
        for (TownStatistics townStatistics : incidents.values()) {
            if (townStatistics.getAccidents() > 3) {
                set.add(townStatistics);
            }
        }
        return set;
    }
}

